package controller;

import model.MySql;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by yvdedu.com on 2016/9/27.
 */
@WebServlet(urlPatterns = "/buy_collect_history")
public class buy_collect_history extends HttpServlet{
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setCharacterEncoding("utf-8");
        req.setCharacterEncoding("utf-8");
        String user_id=req.getParameter("user_id");
        String book_id=req.getParameter("book_id");
        String chapter_id=req.getParameter("chapter_id");
        String status=req.getParameter("status");
        MySql mySql=new MySql();
        if(status.equals("buy")){
            Boolean result=mySql.buyChapter(Integer.parseInt(user_id),Integer.parseInt(chapter_id));
            resp.getWriter().print(result);
        }
        if(status.equals("collect")){
            Boolean result=mySql.colChapter(Integer.parseInt(user_id),Integer.parseInt(book_id));
            resp.getWriter().print(result);
        }
        if(status.equals("history")){
            Boolean result=mySql.hisChapter(Integer.parseInt(user_id),Integer.parseInt(chapter_id));
            resp.getWriter().print(result);
        }
    }
}
